package com.glorysoft.hlgdpda.model

import com.glorysoft.hlgdpda.base.BaseRepository
import com.glorysoft.hlgdpda.base.Constant
import com.glorysoft.hlgdpda.entity.*
import com.glorysoft.hlgdpda.entity.net.BaseResponseBean
import com.google.gson.JsonObject
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

/**
 * FileName: TrackInRepository
 * Author: XJH
 * Date: 2021/5/25 15:06
 * Description:
 * History:
 */
class TaskRepository : BaseRepository() {
    private val MES_URL = "/esbrest/RestService/postrequest"
    /**
     * 获取批次信息
     */
    suspend fun getLotInfo(map: JsonObject): LotEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.LOTQUERY"))
            .toResponse<LotEntity>()
            .await()
    }

    /**
     * 通过载具获取批次信息
     */
    suspend fun getLotInfoByCarrier(map: JsonObject): LotEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.CARRIERIDQUERY"))
            .toResponse<LotEntity>()
            .await()
    }

    /**
     * 获取载具信息
     */
    suspend fun getCarrierInfo(map: JsonObject): CarrierEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.CARRIERIDINFORMATION"))
            .toResponse<CarrierEntity>()
            .await()
    }


    /**
     * 获取工单信息
     */
    suspend fun getWorkInfo(map: JsonObject): LotEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.HLFINDLOTS"))
            .toResponse<LotEntity>()
            .await()
    }

    /**
     * 获取物料信息
     */
    suspend fun getMLotInfo(map: JsonObject): MLotListEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.MLOTKITTINGQUERY"))
            .toResponse<MLotListEntity>()
            .await()
    }

    /**
     * 获取Batch信息
     */
    suspend fun getBatchInfo(map: JsonObject): LotEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.BATCHQUERY"))
            .toResponse<LotEntity>()
            .await()
    }

    /**
     * 进站
     */
    suspend fun batchTrackIn(map: JsonObject): BaseResponseBean<Any> {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.BATCHLOTTRACKIN"))
            .toResponse<BaseResponseBean<Any>>()
            .await()
    }

    /**
     * 进站
     */
    suspend fun defaultTrackIn(map: JsonObject): BaseResponseBean<Any> {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.LOTTRACKIN"))
            .toResponse<BaseResponseBean<Any>>()
            .await()
    }

    /**
     * 出站
     */
    suspend fun defaultTrackOut(map: JsonObject): BaseResponseBean<Any> {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.LOTTRACKOUT"))
            .toResponse<BaseResponseBean<Any>>()
            .await()
    }

    /**
     * 进站
     */
    suspend fun batchTrackOut(map: JsonObject): BaseResponseBean<Any> {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.BATCHLOTTRACKOUT"))
            .toResponse<BaseResponseBean<Any>>()
            .await()
    }

    /**
     * 工单进站
     */
    suspend fun workTrackIn(map: JsonObject): BaseResponseBean<Any> {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.HLWOTRACKIN"))
            .toResponse<BaseResponseBean<Any>>()
            .await()
    }

    /**
     * 工单出站
     */
    suspend fun workTrackOut(map: JsonObject): BaseResponseBean<Any> {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.HLWOTRACKOUT"))
            .toResponse<BaseResponseBean<Any>>()
            .await()
    }

    /**
     * 通过批次，查询当前工步HoldCode、ReleaseCode、DefectCode、ScrapCode、UnScrapCode、ReworkCode
     */
    suspend fun getCodeList(map: JsonObject): CodeListEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"MES.GETSTEPBYLOT"))
            .toResponse<CodeListEntity>()
            .await()
    }

    /**
     * 物料上下机
     */
    suspend fun mLotKitting(map: JsonObject): BaseResponseBean<Any> {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.MLOTKITTING"))
            .toResponse<BaseResponseBean<Any>>()
            .await()
    }

    /**
     * 获取positionName
     */
    suspend fun getPositionName(map: JsonObject): PositionNameEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.POSITIONMANAGE"))
            .toResponse<PositionNameEntity>()
            .await()
    }

    /**
     * 获取positionName
     */
    suspend fun bankShip(map: JsonObject): BaseResponseBean<Any> {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.BANKSHIP"))
            .toResponse<BaseResponseBean<Any>>()
            .await()
    }

    /**
     * 载具绑定批次
     */
    suspend fun carrierBindLot(map: JsonObject): BaseResponseBean<Any> {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.BINDINGCARRIERID"))
            .toResponse<BaseResponseBean<Any>>()
            .await()
    }

    /**
     * 载具解绑批次
     */
    suspend fun carrierUnBindLot(map: JsonObject): BaseResponseBean<Any> {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.UNBINDINGCARRIERID"))
            .toResponse<BaseResponseBean<Any>>()
            .await()
    }

    /**
     * 获取设备信息
     */
    suspend fun getEqpInfo(map: JsonObject): EquipmentEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.EQPQUERY"))
            .toResponse<EquipmentEntity>()
            .await()
    }

    /**
     * 分批出站
     */
    suspend fun spiltTrackOut(map: JsonObject): LotEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.SPLITTRACKOUT"))
            .toResponse<LotEntity>()
            .await()
    }

    /**
     * 获取子批信息
     */
    suspend fun getItemLots(map: JsonObject): LotEntity {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.LOTQUERY"))
            .toResponse<LotEntity>()
            .await()
    }

    /**
     * 获取子批信息
     */
    suspend fun mergeTrackOut(map: JsonObject): Any {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.MERGETRACKOUT"))
            .toResponse<Any>()
            .await()
    }

    /**
     * 出站
     */
    suspend fun scrap(map: JsonObject): Any {
        return RxHttp.postForm(Constant.REQUEST_URL_DEBUG + MES_URL)
            .addAll(getInJsonData(map,"HL.LOTSCRAP"))
            .toResponse<Any>()
            .await()
    }
}